<?php
  include __DIR__."/config/cors.php";
  include __DIR__."/database.php";

  $nid = @$_GET['nid'];
  if(!isset($nid)){
    echo json_encode([
        "code" => 202,
        "msg"=>"缺少必要参数 nid"
    ]);
    exit;
  }

  $db = new DB();
  $sql = "select news.id,news.title,news.context,news.time,news.newImg,user.username from news,user where news.uid = user.id and news.id = $nid";
  $data = $db->selectOne($sql);
  if (is_array($data) and count($data) > 0) {
    echo json_encode([
        "code" => 200,
        "msg"=>"查询成功",
        "data"=>$data
    ]);
}else {
    is_array($data) ? $msg = "查询结果为空" : $msg = "查询失败: ".$data;
    echo json_encode([
       "code" => 201,
       "msg"=> $msg
     ]);
}
?>